package la.bbs558.controller.admin;

import cn.dev33.satoken.annotation.SaCheckRole;
import la.bbs558.aop.valid.Check;
import la.bbs558.aop.valid.Valid;
import la.bbs558.controller.base.Result;
import la.bbs558.entity.UserTag;
import la.bbs558.satoken.StpAdminUtil;
import la.bbs558.service.UserTagService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Shanks
 * @date: 2023/12/18 14:08
 * @desc:
 */
@RestController
@RequestMapping("/admin/userTag")
@RequiredArgsConstructor
@SaCheckRole(value = { "admin" },type = StpAdminUtil.TYPE)
@Check
public class UserTagManageController {

    private final UserTagService userTagService;

    @GetMapping("list")
    public Result<?> list(@RequestParam(defaultValue = "") String tagName) {
        return Result.success(userTagService.getListForAdmin(tagName));
    }

    @PostMapping("add")
    public Result<?> add(@RequestBody UserTag userTag) {
        userTagService.addUserTagForAdmin(userTag);
        return Result.success();
    }

    @PostMapping("update")
    public Result<?> update(@RequestBody @Valid UserTag userTag) {
        userTagService.updateUserTagForAdmin(userTag);
        return Result.success();
    }

    @PostMapping("delete")
    public Result<?> delete(Long id) {
        userTagService.removeById(id);
        return Result.success();
    }
}
